﻿<navigation:Page x:Class="Candy.ProjectsPage" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
                  xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
                 xmlns:gala="http://www.galasoft.ch/mvvmlight"
           d:DesignWidth="1315" d:DesignHeight="755"
           Title="Projects" 
                 xmlns:tlk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                 xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
                 DataContext="{Binding Source={StaticResource Locator}, Path=Projects}" >
	<sdk:Page.Resources>
		<DataTemplate x:Key="MyProjectsDataTemplate">
			<Grid Margin="0,0,0,4">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto"/>
					<ColumnDefinition Width="*"/>
				</Grid.ColumnDefinitions>
				<HyperlinkButton Content="{Binding Entity.Name}" HorizontalAlignment="Left" VerticalAlignment="Top" Command="{Binding Load, Mode=OneWay}"/>
				<TextBlock Grid.Column="1" HorizontalAlignment="Right" Margin="10,0,0,0" TextWrapping="Wrap" Text="{Binding Role}" VerticalAlignment="Center" Style="{StaticResource DefaultLabel}" Opacity="0.31"/>
			</Grid>
		</DataTemplate>
		<DataTemplate x:Key="PublicProjectDataTemplate">
			<Grid Height="Auto" Margin="0,0,0,10">
				<Grid.ColumnDefinitions>
					<ColumnDefinition/>
					<ColumnDefinition Width="Auto"/>
				</Grid.ColumnDefinitions>
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto"/>
					<RowDefinition/>
				</Grid.RowDefinitions>
				<HyperlinkButton Content="{Binding Entity.Name}" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Center" Command="{Binding Join, Mode=OneWay}"/>
				<TextBlock Grid.Column="1" HorizontalAlignment="Right" Margin="0" Text="{Binding Entity.Owner, StringFormat=created by \{0\}}" VerticalAlignment="Center" Style="{StaticResource DefaultLabel}" Opacity="0.6" FontSize="11"/>
                <TextBlock Grid.ColumnSpan="2" ToolTipService.ToolTip="{Binding Entity.Description}" Margin="4,0,0,0" Grid.Row="1" MaxHeight="36" TextWrapping="Wrap" Text="{Binding Entity.Description}" VerticalAlignment="Top" Style="{StaticResource DefaultLabel}" FontStyle="Italic" Opacity="0.78" TextTrimming="WordEllipsis"/>
			</Grid>
		</DataTemplate>
	</sdk:Page.Resources>
    <sdk:Page.Background>
        <StaticResource ResourceKey="WindowBackground"/>
    </sdk:Page.Background>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <gala:EventToCommand Command="{Binding Load}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Grid x:Name="LayoutRoot"  Background="{StaticResource WindowBackground}" Visibility="{Binding IsLoggedIn, Converter={StaticResource VisibilityConverter}}" >
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
          </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Border HorizontalAlignment="Left" Width="450" Background="{StaticResource ControlBackgroundDark}" BorderThickness="0" Margin="8,0,0,0">
        	<Grid Margin="12,0">
        		<Grid.RowDefinitions>
        			<RowDefinition Height="48"/>
        			<RowDefinition Height="Auto"/>
        			<RowDefinition Height="Auto"/>
        			<RowDefinition Height="Auto"/>
					<RowDefinition Height="Auto"/>
					<RowDefinition Height="Auto"/>
					<RowDefinition Height="Auto"/>
					<RowDefinition Height="Auto"/>
					<RowDefinition/>
				
        		</Grid.RowDefinitions>
        		<TextBlock HorizontalAlignment="Left" Margin="8,8,0,8" TextWrapping="Wrap" Text="Projects" VerticalAlignment="Center" FontSize="24"/>
        		<Rectangle Fill="{StaticResource Border}" Height="1" Margin="0" Grid.Row="1" VerticalAlignment="Top" StrokeThickness="0"/>
        		<TextBlock HorizontalAlignment="Left" Margin="8,12,0,0" TextWrapping="Wrap" Text="Start" VerticalAlignment="Bottom" FontSize="18.667" Grid.Row="2"/>
        		<HyperlinkButton Content="New Project..." HorizontalAlignment="Left" Margin="8,10,0,4" Grid.Row="3" VerticalAlignment="Center" Command="{Binding CreateNewProject, Mode=OneWay}"/>
                <TextBlock HorizontalAlignment="Left" Margin="10,4,0,4" Grid.Row="4" TextWrapping="Wrap" Text="{Binding NumberOfProjectsLeft, Mode=OneWay, StringFormat=You have \{0\} project left.}" VerticalAlignment="Center" Opacity="0.6"/>
        		<HyperlinkButton Content="Join other projects" HorizontalAlignment="Left" Margin="8,4,0,4" Grid.Row="5" VerticalAlignment="Center" Command="{Binding ShowPublicProjects, Mode=OneWay}"/>
        		<Rectangle Fill="{StaticResource Border}" Height="1" Margin="0,12,0,13" Grid.Row="6" VerticalAlignment="Top" StrokeThickness="0"/>
                <TextBlock HorizontalAlignment="Left" Margin="8,0,0,0" TextWrapping="Wrap" Text="My projects" VerticalAlignment="Bottom" FontSize="18.667" Grid.Row="7"/>
                <ItemsControl Margin="8" Grid.Row="8" ItemsSource="{Binding Projects}" ItemTemplate="{StaticResource MyProjectsDataTemplate}" ScrollViewer.VerticalScrollBarVisibility="Auto">
                  <ItemsControl.Template>
                        <ControlTemplate>
                            <ScrollViewer Background="Transparent" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Style="{StaticResource DefaultScrollViewer}">
                                <ItemsPresenter />
                            </ScrollViewer>
                        </ControlTemplate>
                    </ItemsControl.Template> 
                </ItemsControl>
                <Button ToolTipService.ToolTip="Reload" HorizontalAlignment="Right" Margin="0,0,8,0" Grid.Row="7" VerticalAlignment="Center" Style="{StaticResource IconButton}" Command="{Binding Load, Mode=OneWay}">
                    <Image Stretch="None" Source="Images/Icons/Reload.png" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0"/>
                </Button>
            </Grid>
        </Border>
        <Border BorderThickness="0" Grid.Column="1" Margin="8,0,3,0" Background="{StaticResource ControlBackgroundDark}" Width="450" HorizontalAlignment="Left" Visibility="{Binding PublicProjectsVisible, Converter={StaticResource VisibilityConverter}}">
        	<Grid Margin="12,0">
        		<Grid.RowDefinitions>
        			<RowDefinition Height="48"/>
        			<RowDefinition Height="Auto"/>
        			<RowDefinition Height="Auto"/>
        			<RowDefinition Height="*"/>
        	
  
				
        		</Grid.RowDefinitions>
        		<Rectangle Fill="{StaticResource Border}" Height="1" Margin="0" Grid.Row="1" VerticalAlignment="Top" StrokeThickness="0"/>
        		<TextBlock HorizontalAlignment="Left" Margin="8,12,0,0" TextWrapping="Wrap" Text="Public projects" VerticalAlignment="Bottom" FontSize="18.667" Grid.Row="2"/>
                <ItemsControl Margin="8,14,8,8" Grid.Row="3" ItemsSource="{Binding OtherProjects}" ItemTemplate="{StaticResource PublicProjectDataTemplate}" ScrollViewer.VerticalScrollBarVisibility="Auto" >
                   <ItemsControl.Template>
                        <ControlTemplate>
                            <ScrollViewer Background="Transparent" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Style="{StaticResource DefaultScrollViewer}">
                                <ItemsPresenter />
                            </ScrollViewer>
                        </ControlTemplate>
                    </ItemsControl.Template> 
                </ItemsControl>
            </Grid>
        </Border>
       
    </Grid>
</navigation:Page>
